package cn.yunhe.control;

import cn.yunhe.entity.Test;
import cn.yunhe.server.TestServer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/InsertTestNameServlet")
public class InsertTestNameServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TestServer testServer = new TestServer();
        PrintWriter out = response.getWriter();
        String tName = request.getParameter("tName");
        if (tName !=null){
            Test test = testServer.SelectTestId(tName);
            if (test == null){ //若查询的值为null说明还没有该试卷名
                boolean flag = testServer.InsertTestName(tName); //插入试卷名称
                if (flag){
                    out.print("true");
                    out.flush();
                }else {
                    out.print("false");
                    out.flush();
                }
            }else {
                out.print("wrong");
                out.flush();
            }

        }else {
            out.print("error");
            out.flush();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
